<link rel="stylesheet" type="text/css" href="<?php echo TEMPLATES_PATH;?>/css/extend.css">
<link rel="stylesheet" type="text/css" href="<?php echo TEMPLATES_PATH;?>/css/hotel.css">
<link rel="stylesheet" type="text/css" href="<?php echo TEMPLATES_PATH;?>/css/airline.css">
<link href="<?php echo TEMPLATES_PATH;?>/css/btn.css" media="all" rel="stylesheet" type="text/css">
<link href="<?php echo TEMPLATES_PATH;?>/css/checkbox.css" media="all" rel="stylesheet" type="text/css">
<link href="<?php echo TEMPLATES_PATH;?>/css/list.css" media="all" rel="stylesheet" type="text/css">
<link href="<?php echo TEMPLATES_PATH;?>/css/base.css" media="all" rel="stylesheet" type="text/css">

<style type="text/css">
.cart_btn_area{ display:-webkit-box; padding:10px;}
.cart_btn_area .cart_btn{ -webkit-box-flex:1;height:30px;margin:0 2px;background-color: #c00000;font-size:14px;text-align: center;line-height: 30px;vertical-align: middle;border-radius: 5px;}
.cart_btn_area .cart_btn a{ display:block; color:#FFF;}
</style>
<header class="layout head padding-small">
    <a href="javascript:back(true);" class="hBack float-left"></a>
    <h4 class="hTxt float-left text-center text-white">礼品兑换</h4>
    <a href="javascript:;" id="btnJdkey" class="hHlep float-right"></a>
</header>

<div id="notEmptyCart" style="display:block">
    
<?php if (!empty($output['cart_array']) && is_array($output['cart_array'])) { ?>
    <?php foreach ($output['cart_array'] as $_k => $_v) { ?>
    <ul class="list"  id="pcart_item_<?php echo $_v['pcart_id']; ?>">
        <li class="row">
            <div>
                <div class="goods-info row">  
                    <a url="index.php?act=pointprod&op=pinfo&id=<?php echo $_v['pgoods_id']?>" onClick="pclicked(this);">
                        <img class="photo" alt="<?php echo $_v['pgoods_name']; ?>" src="<?php echo SiteUrl.DS.$_v['pgoods_image'];?>" onerror="this.src='<?php echo TEMPLATES_PATH;?>/images/touch2013/no_100_100.jpg'">
                    </a>
                    <div class="desc">  
                        <span class="title"><a url="index.php?act=pointprod&op=pinfo&id=<?php echo $_v['pgoods_id']?>" onClick="pclicked(this);">
                            <h4 class="cart_item_text"><?php echo $_v['pgoods_name']; ?></h4></a>
                        </span>             
                        <div class="pay-info cart_item_price">
                            <span class="price">
                                <span class="cart-goods-price-s" ><em><?php echo $_v['pgoods_points']; ?></em></span>
                            </span>
                            <span style="color:#999999;">x</span>
						  <input id="input_item_<?php echo $_v['pcart_id']; ?>" value="<?php echo $_v['pgoods_choosenum']; ?>" changed="<?php echo $_v['pgoods_choosenum']; ?>" onblur="pcart_change_quantity('<?php echo $_v['pcart_id']; ?>', this);" class="amount  cart_item_price" type="text" style="text-align:center;"/>
						 &nbsp;&nbsp;=&nbsp;&nbsp;
						 <span id="item_<?php echo $_v['pcart_id']; ?>_subtotal" class="cart-point mr5"><?php echo $_v['pgoods_pointone']; ?></span> <?php echo $lang['points_unit']; ?>
						 <a class="del" href="javascript:void(0)"  url="index.php?act=pointcart" onclick="if(confirm('是否确认删除？')){drop_pcart_item(<?php echo $_v['pcart_id']; ?>,this);}"></a>
						 
                        </div>
                    </div>                      
                </div>
            </div>
        </li>
    </ul> 
    <?php }?>
    <div id="paymentp" style="padding:10px; line-height:26px; border-bottom: 1px solid #CCC;">
		总积分：<span id="pcart_amount"><?php echo $output['pgoods_pointall']; ?></span> 分
    </div>
	<div class="cart_btn_area">
		<div class="cart_btn">
			<a url="index.php?act=pointprod" onClick="pclicked(this);">继续兑换</a>
        </div>
        <div class="cart_btn">
			<a url="index.php?act=pointcart&op=step1" onClick="pclicked(this);">确认兑换</a>
        </div>
    </div>
 
<?php } else {?>

 <div class="m" id="m" style="padding-bottom:100px;">
        <div class="mc">
            <div class="icon-cart">
                <span></span>
                <p>您的礼品兑换车暂时没有礼品，</p>
                <p>去<a url='index.php?act=pointprod' onClick="pclicked(this);">礼品页&gt;&gt;</a>挑选您喜欢的礼品</p>
            </div>
        </div>
    </div>

<?php }?>

    
</div>

<script type="text/javascript">
//删除兑换积分礼品进货车
function drop_pcart_item(pcart_id,event){
    var tr = $('#pcart_item_' + pcart_id);
    var amount_span = $('#pcart_amount');
    var cart_goods_kinds = $('#cart_goods_kinds');
    $.getJSON('index.php?act=pointcart&op=drop&pc_id=' + pcart_id, function(result){
		 // window.location.reload();    //刷新
        pclicked(event);
    });
}
function pcart_change_quantity(pcart_id, input){
    var amount_span = $('#pcart_amount');
    var subtotal_span = $('#item_' + pcart_id + '_subtotal');
    var quantity_input = $('#input_item_' + pcart_id);
    //暂存为局部变量，否则如果用户输入过快有可能造成前后值不一致的问题
    var _v = input.value;
    $.getJSON('index.php?act=pointcart&op=update&pc_id=' + pcart_id + '&quantity=' + _v, function(result){
        if(result.done){
            //更新成功
            $(input).attr('changed', _v);
            amount_span.html(result.amount);
            subtotal_span.html(result.subtotal);
            quantity_input.val(result.quantity);
        }
        else{
            //更新失败
            alert(result.msg);
            window.location.reload();    //刷新
        }
    });
}
</script>